﻿using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;


namespace SimpleLibrary
{
    public class SqlLoadGenSection : ConfigurationSection
    {
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public DatabaseElementCollections Elements
        {
            get { return (DatabaseElementCollections)base[""]; }
        }

        [ConfigurationProperty("worker", IsRequired = true)]
        public string Worker
        {
            get
            {
                return (string)this["worker"];
            }
            set
            {
                this["worker"] = value;
            }
        }

        [ConfigurationProperty("timeOut", IsRequired = true)]
        public string TimeOut
        {
            get
            {
                return (string)this["timeOut"];
            }
            set
            {
                this["timeOut"] = value;
            }
        }
    }

    public class DatabaseElementCollections : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new DatabaseElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((DatabaseElement)element).Name;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "Database";
            }
        }

        protected override bool IsElementName(string elementName)
        {
            if (string.IsNullOrWhiteSpace(elementName) || elementName != "Task")
                return false;
            return true;
        }

        public DatabaseElement this[int index]
        {
            get
            {
                return (DatabaseElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemoveAt(index);
                BaseAdd(index, value);
            }
        }
    }

    public class DatabaseElement : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("connectionStringKey", IsRequired = true)]
        public string ConnectionStringKey
        {
            get
            {
                return (string)this["connectionStringKey"];
            }
            set
            {
                this["connectionStringKey"] = value;
            }
        }


        [ConfigurationProperty("", IsRequired = true, IsKey = false, IsDefaultCollection = true)]
        public TaskElementCollections TaskElements
        {
            get
            {
                return (TaskElementCollections)base[""];
            }
            set
            {
                base[""] = value;
            }
        }
    }

    public class TaskElementCollections : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new TaskElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((TaskElement)element).Name;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "Task";
            }
        }

        protected override bool IsElementName(string elementName)
        {
            if (string.IsNullOrWhiteSpace(elementName) || elementName != "Task")
                return false;
            return true;
        }

        public TaskElement this[int index]
        {
            get
            {
                return (TaskElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemoveAt(index);
                BaseAdd(index, value);
            }
        }
    }

    public class TaskElement : ConfigurationElement
    {
        [ConfigurationProperty("name", DefaultValue = "0", IsRequired = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }


        [ConfigurationProperty("percentage", DefaultValue = "0", IsRequired = true)]
        [IntegerValidator(ExcludeRange = false, MaxValue = 100, MinValue = 0)]
        public int Percentage
        {
            get
            {
                return (int)this["percentage"];
            }
            set
            {
                this["percentage"] = value;
            }
        }

        [ConfigurationProperty("transaction", DefaultValue = "None", IsRequired = true)]
        public string Transaction
        {
            get
            {
                return (string)this["transaction"];
            }
            set
            {
                this["transaction"] = value;
            }
        }

        [ConfigurationProperty("", IsRequired = true, IsKey = false, IsDefaultCollection = true)]
        public JobElementCollections JobElements
        {
            get
            {
                return (JobElementCollections)base[""];
            }
            set
            {
                base[""] = value;
            }
        }
    }

    public class JobElementCollections : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new JobElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((JobElement)element).Name;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "Job";
            }
        }

        protected override bool IsElementName(string elementName)
        {
            if (string.IsNullOrWhiteSpace(elementName) || elementName != "Job")
                return false;
            return true;
        }

        public JobElement this[int index]
        {
            get
            {
                return (JobElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemoveAt(index);
                BaseAdd(index, value);
            }
        }
    }

    public class JobElement : ConfigurationElement
    {
        [ConfigurationProperty("name", DefaultValue = "NA", IsRequired = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("type", DefaultValue = "NA", IsRequired = true)]
        public string Type
        {
            get
            {
                return (string)this["type"];
            }
            set
            {
                this["type"] = value;
            }
        }

        [ConfigurationProperty("query", DefaultValue = "NA", IsRequired = true)]
        public string Query
        {
            get
            {
                return (string)this["query"];
            }
            set
            {
                this["query"] = value;
            }
        }

        [ConfigurationProperty("dataSource", DefaultValue = "", IsRequired = false)]
        public string DataSource
        {
            get
            {
                return (string)this["dataSource"];
            }
            set
            {
                this["dataSource"] = value;
            }
        }

        [ConfigurationProperty("", IsRequired = true, IsKey = false, IsDefaultCollection = true)]
        public ParameterElementCollections ParameterElements
        {
            get
            {
                return (ParameterElementCollections)base[""];
            }
            set
            {
                base[""] = value;
            }
        }
    }

    public class ParameterElementCollections : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ParamenterElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ParamenterElement)element).Name;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "Parameter";
            }
        }

        protected override bool IsElementName(string elementName)
        {
            if (string.IsNullOrWhiteSpace(elementName) || elementName != "Job")
                return false;
            return true;
        }

        public ParamenterElement this[int index]
        {
            get
            {
                return (ParamenterElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemoveAt(index);
                BaseAdd(index, value);
            }
        }
    }

    public class ParamenterElement : ConfigurationElement
    {
        [ConfigurationProperty("name", DefaultValue = "NA", IsRequired = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("type", DefaultValue = "NA", IsRequired = true)]
        public string Type
        {
            get
            {
                return (string)this["type"];
            }
            set
            {
                this["type"] = value;
            }
        }

        [ConfigurationProperty("dataSourceKey", DefaultValue = "NA", IsRequired = true)]
        public string DataSourceKey
        {
            get
            {
                return (string)this["dataSourceKey"];
            }
            set
            {
                this["dataSourceKey"] = value;
            }
        }

        [ConfigurationProperty("seedKey", DefaultValue = 0, IsRequired = false)]
        public int SeedKey
        {
            get
            {
                return (int)this["seedKey"];
            }
            set
            {
                this["seedKey"] = value;
            }
        }

        [ConfigurationProperty("increment", DefaultValue = 1, IsRequired = false)]
        public int Increment
        {
            get
            {
                return (int)this["increment"];
            }
            set
            {
                this["increment"] = value;
            }
        }
    }
}
